package com.pj.controller;

import com.pj.service.RagFlowDataSetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zzy
 * @date 2025/6/20 10:13
 * @description : ragFlow 数据集（知识库）
 */
@RestController
@RequestMapping("/ragFlow/dataset")
public class RagFlowDataSetController {

    @Autowired
    private RagFlowDataSetService ragFlowDataSetService;

    /**
     * 获取知识库列表
     * @return List<Map<String, Object>>
     */
    @GetMapping("/list")
    public List<Map<String, Object>> listDataset() {
        String ragFlowApi = "/api/v1/datasets";
        return ragFlowDataSetService.listDatasets(ragFlowApi);
    }

    /**
     * 添加知识库
     * @return List<Map<String, Object>>
     */
    @PostMapping("/add")
    public List<Map<String, Object>> addDataset() {
        String ragFlowApi = "/api/v1/datasets";
        Map<String, Object> requestBody = new HashMap<>();
        requestBody.put("name", "api测试");
        requestBody.put("description", "这是一个API测试创建的数据集");
        requestBody.put("permission", "me");
        requestBody.put("chunk_method", "naive");

        return ragFlowDataSetService.addDataset(ragFlowApi, requestBody);
    }



}